﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Transactions;
using IssueTracker.Data;
using IssueTracker.Business.Entity;

namespace IssueTracker.Business.BO
{
    public class IssueCustomTypeValueBO
    {

  
        private IssueCustomTypeValueDataAccess da;

        public IssueCustomTypeValueBO() 
        {
            da = new IssueCustomTypeValueDataAccess();
        }


#region Business Methods

        /// <summary>
        /// Add a new IssueCustomTypeValue
        /// </summary>
        /// <param name="issueCustomTypeValue"></param>
        /// <returns></returns>
        public IssueCustomTypeValue AddNew(IssueCustomTypeValue issueCustomTypeValue)
        {
            IssueCustomTypeValue returnIssueCustomTypeValue;

            issueCustomTypeValue.CreationDate = DateTime.Today.Date;

            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
            {
                try
                {
                    returnIssueCustomTypeValue = da.Create(issueCustomTypeValue);
                    ts.Complete();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                
            }

            return returnIssueCustomTypeValue;

        }

        public IssueCustomTypeValue UpdateIssueCustomTypeValue(IssueCustomTypeValue issueCustomTypeValue)
        {
            IssueCustomTypeValue returnIssueCustomTypeValue;

            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
            {
                try
                {
                    returnIssueCustomTypeValue = da.Update(issueCustomTypeValue);
                    ts.Complete();
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                
                return returnIssueCustomTypeValue;
            }
        }

        public void DeleteIssueCustomTypeValue(IssueCustomTypeValue issueCustomTypeValue)
        {
            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
            {
                try
                {
                    da.Delete(issueCustomTypeValue);
                    ts.Complete();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }

        public IEnumerable<IssueCustomTypeValue> ListIssueCustomTypeValues()
        {
            IssueCustomTypeValueDataAccess data = new IssueCustomTypeValueDataAccess();

            IEnumerable<IssueCustomTypeValue> returnList = data.List();
            return returnList;
        }

        public IssueCustomTypeValue GetIssueCustomTypeValue(System.Guid id)
        {
            return da.Retrieve(id);
        }

        public IEnumerable<IssueCustomTypeValue> ListIssueCustomTypeValuesByRef(System.Guid reference)
        {
            return da.ListByReferenceId(reference);
        }
#endregion
        
   
    }
}
